class Singleton {
    //饿汉模式： 线程安全
    private static Singleton instance = new Singleton();

    public static Singleton getInstance() {
        return instance;
    }

    private Singleton() { }
}

public class demo17 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();

        if(s1 == s2 ){
            System.out.println("单例模式成功！");
        } else {
            System.out.println("失败");
        }

//        Singleton S3 = new Singleton();
//        if(s1 == S3 ){
//            System.out.println("单例模式成功！");
//        } else {
//            System.out.println("失败");
//        }
    }
}
